package com.wd.live.model;

import android.content.Context;
import android.content.SharedPreferences;

public class SpUtils {
    private static SharedPreferences sp;
    public static synchronized void init(Context context){
        //判断
        if(sp==null){
            //创建
            sp=context.getSharedPreferences("sp_",Context.MODE_PRIVATE);
        }
    }

    public static void putString(String key,String value){
        //存值
        sp.edit().putString(key, value).commit();
    }

    public static void putBoolean(String key,boolean b){
        sp.edit().putBoolean(key, b).commit();
    }

    public static String  getString(String key,String defaultvalue){
        //取值
        return sp.getString(key, defaultvalue);
    }
    //是否是第一次打开
    public static boolean isFirstOpen(){
        boolean isFirstOpen = sp.getBoolean("isFirstOpen", true);
        SharedPreferences.Editor edit = sp.edit();
        if(!isFirstOpen){
            return false;
        }else{
            edit.putBoolean("isFirstOpen",false);
            edit.commit();
            return true;
        }
    }

    public static void clear(){
        sp.edit().clear();
        sp.edit().commit();
    }
    public static boolean getBoolean(String key,Boolean b){
        return sp.getBoolean(key,b);
    }
}
